﻿
@{
    ViewBag.Title = "病人基本信息";
    Layout = "~/Views/Shared/_Form.cshtml";
}
<style>
    span {
    color:red
    }
</style>
<form id="form1">
    <table class="form" style="width: 98%; border: 0">
        <tr>
            <td class="formTitle">
                <span>*</span>卡号：
            </td>
            <td class="formValue">
                <input type="text" id="kh" class="form-control form-an">
            </td>
            <td class="formTitle"><span>*</span>病历号：</td>
            <td class="formValue">
                <input type="text" id="blh" class="form-control form-an">
                <input hidden id="py" />
                <input hidden id="txtghks" />
                <input hidden id="txtghys" />
                <input hidden id="txtghksmc">
                <input hidden id="txtghpbId" />
            </td>
        </tr>
        <tr>
            <td class="formTitle"><span>*</span>患者姓名：</td>
            <td class="formValue">
                <input type="text" id="xm" name="xm" class="form-control form-an">
            </td>
            <th class="formTitle">
                <span class="required">*</span>挂号排班：
            </th>
            <td class="formValue">
                <input type="text" class="form-control" id="txtghpbchoose" />
            </td>
            
        </tr>
        <tr>
            <td class="formTitle"><span>*</span>患者性质：</td>
            <td class="formValue">
                <input type="text" id="brxzmc" name="brxzmc" class="form-control form-an">
            </td>
            <td class="formTitle"><span>*</span>性别：</td>
            <td class="formValue">
                <div class="btn-group" data-toggle="buttons">
                    <label class="btn btn-default">
                        <input type="radio" id="xb" value="1" name="xb" class="form-control form-an">
                        男
                    </label>
                    <label class="btn btn-default">
                        <input type="radio" id="xb" value="2" name="xb" class="form-control form-an">
                        女
                    </label>
                </div>
            </td>
        </tr>
    </table>
</form>

<script>
    $(function () {
        initControl();
        //根据姓名获得拼音
        $('#xm').keyup(function () {
            $('#py').val($(this).toShouPin());
        });

        $("#brxzmc").attr("data-label", "0");
        $("#brxzmc").val("自费");
    });

    function initControl() {
        ///报销政策
        $("#brxzmc").newtouchBatchFloatingSelector({
            height: 200,
            width: 400,
            clickautotrigger: true,
            filter: function (keyword) {
                //遍历数据源，用keyword来筛选出结果
                var resultObjArr = new Array();
                $.each(top.window.clients.sysPatientNatureList, function (idx, val) {
                    if ((val.py && val.py.toLowerCase().indexOf(keyword.toLowerCase()) >= 0) ||
                        keyword.trim() == "" ||
                        (val.brxzmc && val.brxzmc.toLowerCase().indexOf(keyword) >= 0)) {
                        resultObjArr.push(val);
                    }
                });
                return resultObjArr;

            },
            caption: "病人性质",
            colModel: [
                { label: '编码', name: 'brxz', widthratio: 25 },
                { label: '名称', name: 'brxzmc', widthratio: 25 },
                { label: '拼音', name: 'py', widthratio: 25 }
            ],
            itemdbclickhandler: function ($thistr) {
                $("#brxzmc").attr("data-label", $thistr.attr('data-brxz'));
                $("#brxzmc").val($thistr.attr('data-brxzmc'));
                return;
            }
        });


        //挂号排班浮层
        $("#txtghpbchoose").newtouchBatchFloatingSelector({
            height: 150,
            width: 400,
            clickautotrigger: true,
            id: 'regSchedule',
            url: '/OutpatientManage/OutpatientReg/GetRegScheduleList',
            ajaxmethod: 'POST',
            ajaxreqdata: function () {
                var reqData = {};
                reqData.keyword = $("#txtghpbchoose").val();
                reqData.mzlx = "1";//默认普通门诊
                return reqData;
            },
            caption: "挂号排班",
            colModel: [
                { label: '挂号科室', name: 'ksmc', widthratio: 25 },
                { label: '医生', name: 'rymc', widthratio: 20 },
                { label: '挂号项目', name: 'sfxmmc', widthratio: 25 },
                { label: '诊疗项目', name: 'zlxmmc', widthratio: 25 },
                { label: 'ks', name: 'ks', hidden: true },
                { label: 'gh', name: 'gh', hidden: true },
                { label: 'ghlx', name: 'ghlx', hidden: true },
                { label: 'zlxm', name: 'zlxm', hidden: true },
                { label: 'ghpbId', name: 'ghpbId', hidden: true },
            ],
            itemdbclickhandler: function ($thistr) {
                $("#txtghpbchoose").val($thistr.attr('data-ksmc'));
                $("#txtghpbId").val('');
                $("#txtghks").val($thistr.attr('data-ks'));
                $("#txtghys").val($thistr.attr('data-gh'));
                $("#txtghksmc").html($thistr.attr('data-ksmc'));
                $("#txtghpbId").val($thistr.attr('data-ghpbId'));
                return;
            }
        });

        $("#kh").attr("disabled", "disabled").css("background-color", "#f1f4f6");
        $("#blh").attr("disabled", "disabled").css("background-color", "#f1f4f6");
        $.ajax({
            url: "/PatientManage/HospiterRes/GetNewCardNoAndBLH",
            data: { khsc: true, blhsc: true },
            dataType: "json",
            async: false,
            cache: false,
            success: function (data) {
                $('#kh').val(data.kh);
                $('#blh').val(data.blh);
            }
        });
    }

    function submitForm(callBack) {
        var result = checkNotNull();
        if (result) {
            var data = $("#form1").formSerialize();
            data.brxz = $("#brxzmc").attr("data-label");
            data.ks = $('#txtghks').val();
            data.ghpbId = $('#txtghpbId').val();
            data.ys = $('#txtghys').val();
            $.submitForm({
                url: "@Url.Action("SubmitPhysicalexamForm")",
                param: { dto: data },
                success: function (resp) {
                    if (resp.state == "success") {
                        var respjson = JSON.parse(resp.data);
                        data.mzh = respjson.Item1;
                        data.patid = respjson.Item2;
                        data.cardType = "1";
                    }
                    callBack(data);
                    $.modalClose();
                }
            });
        }
    }


    function checkNotNull() {
        //卡号
        var kh = $("#kh").val();
        if (!kh) {
            $.modalAlert("请填写卡号！", 'warning');
            return false;
        }
        //病历号
        var blh = $("#blh").val();
        if (!blh) {
            $.modalAlert("请填写病历号！", 'warning');
            return false;
        }
        //姓名
        var xm = $("#xm").val();
        if (!xm) {
            $.modalAlert("请填写姓名！", 'warning');
            return false;
        }

        //病人性质
        var brxzmc = $("#brxzmc").val();
        if (!brxzmc) {
            $.modalAlert("请选择病人性质！", 'warning');
            return false;
        }

        //拼音
        var py = $("#py").val();
        if (!py) {
            if (!!$("#xm").val()) {
                py = $("#xm").toShouPin();
            }
            if (!py) {
                $.modalAlert("拼音为空！", 'warning');
                return false;
            }
            else {
                $("#py").val(py);
            }
        }

        //性别
        var xb = false;
        $('input[name="xb"]').each(function () {
            var $this = $(this);
            if ($this.parent().hasClass("active")) {
                xb = true;
                $("#xb").val();
            }
        });
        if (!xb) {
            $.modalAlert("请选中性别！", 'warning');
            return false;
        }

        if (!!!$('#txtghpbId').val()) {
            $.modalAlert("请选择排班!", 'warning');
            return false;
        }

        return true;
    }
</script>